#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>

#include "csc.h"
#include "BMPFile.h"

#define YUV422_ROUNDUP(x)	((x) + ((x) & 1))

#define TEST_TIMES	1000

int main()
{
	struct timeval begin, end;
	BMPFile bmpFile;
	bmpFile.Init("test.bmp");

	BMPFile::ImageInfo imageInfo;
	bmpFile.GetImageInfo(imageInfo);

	u8 *p = (u8 *)malloc(imageInfo.w * (imageInfo.bpp / 8));
	u8 *dst = (u8 *)malloc(YUV422_ROUNDUP(imageInfo.w) * 2);
	u32 h;

	bmpFile.ReadScanline(p, imageInfo.w * (imageInfo.bpp / 8), 1);
	gettimeofday(&begin, NULL);
	for (int i = 0; i < TEST_TIMES; i++) {
		h = imageInfo.h;
		while (h--) {
			__BGR888toYUV422(p, dst, imageInfo.w);
		}
	}
	gettimeofday(&end, NULL);

	printf("asm: %d msec for %d times\n", (end.tv_sec - begin.tv_sec) * 1000 + ((end.tv_usec - begin.tv_usec) / 1000));

	gettimeofday(&begin, NULL);
	for (int i = 0; i < TEST_TIMES; i++) {
		h = imageInfo.h;
		while (h--) {
			__BGR888toYUV422_C(p, dst, imageInfo.w);
		}
	}
	gettimeofday(&end, NULL);

	printf("asm: %d msec for %d times\n", (end.tv_sec - begin.tv_sec) * 1000 + ((end.tv_usec - begin.tv_usec) / 1000));
	return 0;
}
